package com.iplatform.iplatformuser.function.group.api.v1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iplatform.iplatformuser.common.ResponseMsg;
import com.iplatform.commons.pagination.Pagination;
import com.iplatform.iplatformuser.framework.util.UniqueIDGenerator;
import com.iplatform.module.privilege.group.*;
import com.iplatform.iplatformuser.function.group.service.inter.IPriGroupService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.iplatform.iplatformuser.common.ConstantUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author heng
 *
 */
@Api(tags ="权限组接口")
@Controller
@RequestMapping("/api/v1/groups")
public class ApiPriGroupController {

	@Autowired
	private IPriGroupService service;

	@Value("${spring.datasource.driver-class-name}")
	private  String dataSource;

	@ApiOperation(value="查询权限组列表（分页）")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="groupName", value="权限组名称", required=false)
	})
	@RequestMapping(value="query", method= RequestMethod.POST)
	public ResponseEntity<PageInfo<PriGroupInfoBean>> query(HttpServletRequest request,
                                                            @RequestParam @ApiParam(hidden=true) Map<String, String> formMap,
                                                            @ApiParam(hidden = true) @ModelAttribute(value = "pagination") Pagination pagination){
		if("com.mysql.jdbc.Driver".equals(dataSource)) {
			List<PriGroupInfoBean> resultList=new ArrayList<>();
			List<PriGroupInfoBean> bean = service.queryGroupByName(formMap);
			for(PriGroupInfoBean test : bean) {
				PriGroupInfoBean tmp=new PriGroupInfoBean();
				try {
					tmp=(PriGroupInfoBean) test.clone();
				} catch (CloneNotSupportedException e) {
					e.printStackTrace();
				}
				tmp.setChild(null);
				tmp.setGroupName(space(tmp.getGroupName(),tmp.getLevel()));
				resultList.add(tmp);
				getChildList(resultList, test);
			}
			if(formMap.get("groupName")!=null&&formMap.get("groupName")!="") {
				List<PriGroupInfoBean> list=new ArrayList<>();
				for (int i = 0; i < resultList.size(); i++) {
					if(resultList.get(i).getGroupName().contains(formMap.get("groupName"))) {
						list.add(resultList.get(i));
					}
				}
				resultList.clear();
				resultList=list;
			}
			PageInfo<PriGroupInfoBean> pageInfo = new PageInfo<>();
			pageInfo.setTotal(resultList.size());
			pageInfo.setPages(resultList.size()/pagination.getPageSize()+1);
			pageInfo.setPageNum(pagination.getPageNum());
			pageInfo.setPageSize(pagination.getPageSize());
			List<PriGroupInfoBean> list=resultList.subList((pagination.getPageNum()-1)*pagination.getPageSize(),
					(pagination.getPageNum()-1)*pagination.getPageSize()+pagination.getPageSize()<resultList.size()?
							(pagination.getPageNum()-1)*pagination.getPageSize()+pagination.getPageSize():resultList.size());
			pageInfo.setList(list);

			return new ResponseEntity<>(pageInfo, HttpStatus.OK);
		}else {
			PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
			List<PriGroupInfoBean> resultList = service.queryGroupByName(formMap);

			PageInfo<PriGroupInfoBean> pageInfo = new PageInfo<>(resultList);

			pagination.setTotalCount(pageInfo.getTotal());
			pagination.setTotalPageNum(pageInfo.getPages());

			return new ResponseEntity<>(pageInfo, HttpStatus.OK);
		}
	}

	@ApiOperation(value="查询权限组列表")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="groupName", value="权限组名称", required=false)
	})
	@RequestMapping(value="queryAll", method= RequestMethod.POST)
	public ResponseEntity<List<PriGroupInfoBean>> queryAll(HttpServletRequest request,
                                                           @RequestParam @ApiParam(hidden=true) Map<String, String> formMap){

		List<PriGroupInfoBean> resultList = service.queryGroupByName(formMap);

		return new ResponseEntity<>(resultList, HttpStatus.OK);
	}


	@ApiOperation(value="根据ID删除权限组信息")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="deleteId", value="权限组ID", required=true)
	})
	@ResponseBody
	@RequestMapping(value="deleteGroupById", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> deleteGroupById(HttpServletRequest request,
                                                       @RequestParam @ApiParam(hidden=true) Map<String, String> formMap){

		service.deleteGroupById(formMap.get("deleteId"));
		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation(value="更新权限组信息")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType="String", paramType="query", name="groupCode", value="权限组编码", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="parentId", value="上级ID", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="groupLevel", value="层级", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="groupName", value="权限组名称", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="groupOrderNo", value="权限组排序", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="remark", value="备注", required=false),
		@ApiImplicitParam(dataType="String", paramType="query", name="groupId", value="权限组id", required=true)

	})
	@ResponseBody
	@RequestMapping(value="updateGroup", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> updateGroup(HttpServletRequest request,
                                                   @RequestParam @ApiParam(hidden=true) Map<String, String> formMap){
//		PriManagerBean priManager = (PriManagerBean) session.getAttribute(PrivilageConstants.PRI_MANAGER);
//		formMap.put("updatedBy", priManager.getUserCode());
		service.updateGroup(formMap);
		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}


	@ApiOperation(value = "删除多个权限组")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "deleteIds", value = "用户ID集合，逗号分隔",
        		required = true, paramType = "query")})
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
		@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范") })
	@ResponseBody
	@RequestMapping(value = "del", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> del(@RequestParam String deleteIds) {

		service.batchDeleteGroup(deleteIds.split(","));

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation(value = "添加权限组")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "parentId", value = "父级ID", required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "groupCode", value = "编码", required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "groupName", value = "名称", required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "remark", value = "描述", required = false, paramType = "query")
	})
	@ResponseBody
	@RequestMapping(value="addGroup", method= RequestMethod.POST)
	public ResponseEntity<ResponseMsg> addGroup(HttpServletRequest request,
                                                @RequestParam @ApiParam(hidden=true) Map<String, String> formMap) {

		formMap.put("groupId",UniqueIDGenerator.getUUID());
		formMap.put("parentId", StringUtils.isEmpty(formMap.get("parentId"))?"0" : formMap.get("parentId"));
		formMap.put("remark", StringUtils.isEmpty(formMap.get("remark"))?"" : formMap.get("remark"));
		service.insertGroup(formMap);

		return new ResponseEntity<>(new ResponseMsg(formMap.get("groupId")), HttpStatus.OK);
	}


	@ApiOperation(value = "获取未和权限组绑定的资源列表")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "resName", value = "资源名称/资源类型",
				required = false, paramType = "query")
	})
	@RequestMapping(value = "getOutRes", method = RequestMethod.POST)
	public ResponseEntity<List<Map<String, String>>> getOutRes(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<Map<String, String>> resList = service.listSelectWithOutResource(formMap);

		return new ResponseEntity<>(resList, HttpStatus.OK);
	}

	@ApiOperation(value = "获取已和权限组绑定的资源列表")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "resName", value = "资源名称/资源类型",
				required = false, paramType = "query")
	})
	@RequestMapping(value = "getInRes", method = RequestMethod.POST)
	public ResponseEntity<List<Map<String, String>>> getInRes(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<Map<String, String>> resList = service.listSelectWithInResource(formMap);

		return new ResponseEntity<>(resList, HttpStatus.OK);
	}



	@ApiOperation(value = "绑定资源")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "checkedIds", value = "资源ID集合，逗号分隔",
				required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "resType", value = "资源类别",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "bindResource", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> bindResource(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		service.updateGroupResource(formMap);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}


	@ApiOperation(value = "查询权限组绑定的角色")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "roleName", value = "角色名称",required = false, paramType = "query")
	})
	@RequestMapping(value = "queryInBindRoleList", method = RequestMethod.POST)
	public ResponseEntity<List<Map<String, String>>> queryInBindRoleList(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<Map<String, String>> resList = new ArrayList<>();
		if(!StringUtils.isEmpty(formMap.get("groupId"))) {
			resList = service.queryInBindRoleList(formMap);
		}
		return new ResponseEntity<>(resList, HttpStatus.OK);
	}

	@ApiOperation(value = "查询权限组没有绑定的角色")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "roleName", value = "角色名称",required = false, paramType = "query")
	})
	@RequestMapping(value = "queryOutBindRoleList", method = RequestMethod.POST)
	public ResponseEntity<List<Map<String, String>>> queryOutBindRoleList(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<Map<String, String>> resList = service.queryOutBindRoleList(formMap);

		return new ResponseEntity<>(resList, HttpStatus.OK);
	}


	@ApiOperation(value = "绑定角色")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "checkedIds", value = "角色ID集合，逗号分隔",
				required = false, paramType = "query")
	})
	@RequestMapping(value = "bindRole", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> bindRole(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		formMap.put("mediumType", ConstantUtil.ROLE);
		service.insertGroupMeduim(formMap);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}


	@ApiOperation(value = "根据groupId查询菜单（树状结构）")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query")
	})
	@RequestMapping(value = "queryMenuTreeByGroupId", method = RequestMethod.GET)
	public ResponseEntity<JSONObject> queryMenuTreeByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<PriResourcesTree> resourcesTreeList = service.queryMenuTreeByGroupId(formMap);
		JSONObject json = new JSONObject();
		json.put("code", 200);
		json.put("msg", "");
		json.put("status", 0);
		json.put("count", resourcesTreeList.size());
		json.put("data", resourcesTreeList);
		return new ResponseEntity<>(json, HttpStatus.OK);
	}

	@ApiOperation(value = "根据groupId查询专业（树状结构）")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "validDate", value = "有效时间，格式YYYY",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "querySpecTreeByGroupId", method = RequestMethod.GET)
	public ResponseEntity<JSONObject> querySpecTreeByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		List<PriResourcesTree> resourcesTreeList = service.querySpecTreeByGroupId(formMap);
		JSONObject json = new JSONObject();
		json.put("code", 200);
		json.put("msg", "");
		json.put("status", 0);
		json.put("count", resourcesTreeList.size());
		json.put("data", resourcesTreeList);
		return new ResponseEntity<>(json, HttpStatus.OK);
	}

	@ApiOperation(value = "根据groupId查询单位（树状结构）")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query")
	})
	@RequestMapping(value = "queryOrgTreeByGroupId", method = RequestMethod.GET)
	public ResponseEntity<JSONObject> queryOrgTreeByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		List<PriResourcesTree> resourcesTreeList = service.queryOrgTreeByGroupId(formMap);
		JSONObject json = new JSONObject();
		json.put("code", 200);
		json.put("msg", "");
		json.put("status", 0);
		json.put("count", resourcesTreeList.size());
		json.put("data", resourcesTreeList);
		return new ResponseEntity<>(json, HttpStatus.OK);
	}

	@ApiOperation(value = "根据groupId查询单位（树状结构）")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
				required = true, paramType = "query")
	})
	@RequestMapping(value = "queryManagerOrgTreeByGroupId", method = RequestMethod.GET)
	public ResponseEntity<JSONObject> queryManagerOrgTreeByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		List<PriResourcesTree> resourcesTreeList = service.queryManagerOrgTreeByGroupId(formMap);
		JSONObject json = new JSONObject();
		json.put("code", 200);
		json.put("msg", "");
		json.put("status", 0);
		json.put("count", resourcesTreeList.size());
		json.put("data", resourcesTreeList);
		return new ResponseEntity<>(json, HttpStatus.OK);
	}

	@ApiOperation(value = "根据groupId查询指标")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "resName", value = "指标的名称",
		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "targetType", value = "指标的类型",
		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "selectType", value = "已选/未选，取值 selected/notSelect",
		required = true, paramType = "query"),
	})
	@RequestMapping(value = "queryTargetByGroupId", method = RequestMethod.POST)
	public ResponseEntity<List<PriResourcesTree>> queryTargetByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<PriResourcesTree> priResourcesTree = service.queryTargetByGroupId(formMap);

		return new ResponseEntity<>(priResourcesTree, HttpStatus.OK);
	}




	@ApiOperation(value = "权限组绑定操作")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "checkIds", value = "操作ID集合，逗号分隔",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "insertGroupOpt", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> insertGroupOpt(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		formMap.put("createBy", "wangxi");
		service.insertGroupOpt(formMap);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}



	/**
	 * 查询权限组名称
	 * @param formMap
	 * @param pagination
	 * @return
	 */
	@ApiOperation(value = "查询权限组名称列表")
	@RequestMapping(value = "/queryGroupNameList", method = RequestMethod.POST)
	public ResponseEntity<JSONObject> queryGroupNameList() {

		List<HashMap<String, String>> resultList = service.queryGroupName();

		JSONObject allObject = new JSONObject();
		JSONArray arrayName = new JSONArray();

		for(Map<String, String> nameList : resultList) {
			JSONObject objectName = new JSONObject();
			objectName.put("groupName", nameList.get("groupName"));
			arrayName.add(objectName);
		}
		allObject.put("name", arrayName);
		return new ResponseEntity<>(allObject, HttpStatus.OK);
	}

	@ApiOperation(value = "根据权限组ID查询数据包")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query")
	})
	@RequestMapping(value = "/queryDataSetByGroupId", method = RequestMethod.POST)
	public ResponseEntity<List<DataSetCategory>> queryDataSetByGroupId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<DataSetCategory> list = service.queryDataSet(formMap);

		return new ResponseEntity<>(list, HttpStatus.OK);
	}


	@ApiOperation(value = "增加权限组数据包绑定")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupDataSetJson", value = "权限组绑定数据集JSON",
        		required = true, paramType = "query")
	})
	@RequestMapping(value = "/addGroupDataSet", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> addGroupDataSet(@RequestParam String groupDataSetJson) {

		service.addGroupDataSet(groupDataSetJson);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation(value = "根据权限组ID和数据包ID查询绑定的字段")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "setId", value = "数据包ID",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "/queryColumnByGroupIdAndSetId", method = RequestMethod.POST)
	public ResponseEntity<List<DataSetColumn>> queryColumnByGroupIdAndSetId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		List<DataSetColumn> dataSetColumnList = service.queryColumnByGroupIdAndSetId(formMap);

		return new ResponseEntity<>(dataSetColumnList, HttpStatus.OK);
	}


	@ApiOperation(value = "增加权限组和数据包的字段的绑定")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "setId", value = "数据包ID",
		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "selectIds", value = "字段ID集合，逗号分隔",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "/addGroupSetColumn", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> addGroupSetColumn(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		service.addGroupSetColumn(formMap);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation(value = "根据权限组ID和数据包ID查询行权限")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupId", value = "权限组ID",
        		required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "setId", value = "数据包ID",
		required = true, paramType = "query")
	})
	@RequestMapping(value = "/queryRowByGroupIdAndSetId", method = RequestMethod.POST)
	public ResponseEntity<GroupDataSetRow> queryRowByGroupIdAndSetId(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {

		GroupDataSetRow groupDataSetRow = service.queryRowByGroupIdAndSetId(formMap);

		return new ResponseEntity<>(groupDataSetRow, HttpStatus.OK);
	}


	@ApiOperation(value = "增加权限组和行条件的绑定")
	@ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "groupRowJson", value = "JSON",
        		required = true, paramType = "query")
	})
	@RequestMapping(value = "/addGroupDataSetRow", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg> addGroupDataSetRow(@RequestParam String groupRowJson) {

		GroupDataSetRow groupDataSetRow = new Gson().fromJson(groupRowJson, GroupDataSetRow.class);

		service.addGroupDataSetRow(groupDataSetRow);

		return new ResponseEntity<>(new ResponseMsg(ConstantUtil.SUCCESS), HttpStatus.OK);
	}

	@ApiOperation(value = "查询用户对应的可用的数据包")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryDataSetIdByGroup", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryDataSetIdByGroup(@RequestParam String userId) {

        List<String> queryDataSetIdByGroup = service.queryDataSetIdByGroup(userId);

        return new ResponseEntity<>(queryDataSetIdByGroup, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户对应绑定的可用的数据包,的可用column的id")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "dataSetId", value = "dataSetId",
        required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryDataSetColIdByGroup", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryDataSetColIdByGroup(@RequestParam String userId, @RequestParam String dataSetId) {

        List<String> queryDataSetColIdByGroup = service.queryDataSetColIdByGroup(userId, dataSetId);

        return new ResponseEntity<>(queryDataSetColIdByGroup, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户对应绑定的可用的数据包的可用column别名")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query"),
        @ApiImplicitParam(dataType = "String", name = "dataSetId", value = "dataSetId",
        required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryDataSetColAliasByGroup", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryDataSetColAliasByGroup(@RequestParam String userId, @RequestParam String dataSetId) {

        List<String> queryDataSetColAliasByGroup = service.queryDataSetColAliasByGroup(userId, dataSetId);

        return new ResponseEntity<>(queryDataSetColAliasByGroup, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户，对应权限组 绑定的专业")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryUseSpecByUserId", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryUseSpecByUserId(@RequestParam String userId) {

        List<String> specIds = service.queryUseSpecByUserId(userId);

        return new ResponseEntity<>(specIds, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户，对应权限组 绑定的组织单位")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryUseOrgByUserId", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryUseOrgByUserId(@RequestParam String userId) {

        List<String> specIds = service.queryUseOrgByUserId(userId);

        return new ResponseEntity<>(specIds, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户，对应权限组 绑定的组织单位")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryUseManagerOrgByUserId", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryUseManagerOrgByUserId(@RequestParam String userId) {

        List<String> specIds = service.queryUseManagerOrgByUserId(userId);

        return new ResponseEntity<>(specIds, HttpStatus.OK);
    }

	@ApiOperation(value = "查询用户，对应权限组 绑定的专业名称")
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "String", name = "userId", value = "userId",
                required = true, paramType = "query")
    })
    @RequestMapping(value = "/queryUseSpecNameByUserId", method = RequestMethod.POST)
    public ResponseEntity<List<String>> queryUseSpecNameByUserId(@RequestParam String userId) {

        List<String> specs = service.queryUseSpecNameByUserId(userId);

        return new ResponseEntity<>(specs, HttpStatus.OK);
    }

	private String space(String name, int level) {
		StringBuilder sb=new StringBuilder();
		for (int i = 1; i < level; i++) {
			sb.append("        ");
		}
		System.out.println(sb.toString()+name);
		return sb.toString()+name;
	}

	public void getChildList(List<PriGroupInfoBean> testList, PriGroupInfoBean test) {
		List<PriGroupInfoBean> child = test.getChild();
		for(PriGroupInfoBean chilTest : child) {
			PriGroupInfoBean tmp=new PriGroupInfoBean();
			try {
				tmp=(PriGroupInfoBean) chilTest.clone();
			} catch (CloneNotSupportedException e) {
				e.printStackTrace();
			}
			tmp.setChild(null);
			tmp.setGroupName(space(tmp.getGroupName(),tmp.getLevel()));
			testList.add(tmp);
			getChildList(testList, chilTest);
		}
	}

}
